/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 22-nov-2010, 17:41:06
 */

package es.unavarra.mti.iws.gui;

import es.unavarra.mti.iws.Manager;
import es.unavarra.mti.iws.logic.properties.PropertiesTableModel;
import es.unavarra.mti.iws.model.Fire;
import es.unavarra.mti.iws.model.Link;
import es.unavarra.mti.iws.model.Node;
import es.unavarra.mti.iws.model.Quake;
import es.unavarra.mti.iws.model.Rain;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

/**
 *
 * @author marcelo
 */
public class MainFrame extends javax.swing.JFrame {
    private Manager manager;
    private PropertiesTableModel model;
    private RenderPanel panel;
    private String fileName = "";
    private boolean saved = true;

    /** Creates new form MainFrame */
    public MainFrame(Manager manager,RenderPanel panel) {

         _instance = this;
        document = new DefaultStyledDocument();
        normalStyle = document.addStyle("Normal Style", null);
        errorStyle = document.addStyle("Error Style", null);
        fatalErrorStyle = document.addStyle("FatalError Style", null);
        warningStyle = document.addStyle("Warning Style", null);
        infoStyle = document.addStyle("Info Style", null);
        StyleConstants.setForeground(normalStyle, Color.BLACK);
        StyleConstants.setForeground(errorStyle, Color.RED);
        StyleConstants.setForeground(fatalErrorStyle, Color.RED);
        StyleConstants.setUnderline(fatalErrorStyle, true);
        StyleConstants.setForeground(infoStyle, Color.GREEN);
        StyleConstants.setForeground(warningStyle, Color.MAGENTA);
        this.manager = manager;
        this.panel = panel;
        model = new PropertiesTableModel(manager);
        initComponents();
        undoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        redoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        String path = "/es/unavarra/mti/iws/resources/";
        try {
            setIconImage( ImageIO.read(getClass().getResource(path + "appIcon.png")) );

        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    private StyledDocument document;
    private Style normalStyle, errorStyle, fatalErrorStyle, warningStyle, infoStyle;

    private static MainFrame _instance;

    public static MainFrame getInstance(){
        return _instance;
    }

    public synchronized void log(String s) {
        try {
            document.insertString(document.getLength(), s + "\n", normalStyle);
            scrollDown();
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }

    public synchronized void error(String s) {
        try {
            document.insertString(document.getLength(), s + "\n", errorStyle);
            scrollDown();
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }

    public synchronized void fatalError(String s) {
        try {
            document.insertString(document.getLength(), s + "\n", fatalErrorStyle);
            scrollDown();
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }

    public synchronized void info(String s) {
        try {
            document.insertString(document.getLength(), s + "\n", infoStyle);
            scrollDown();
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }

    public synchronized void warning(String s) {
        try {
            document.insertString(document.getLength(), s + "\n", warningStyle);
            scrollDown();
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }

    private void scrollDown(){
        SwingUtilities.invokeLater(new Runnable() {
        public void run() {
              textPane.scrollRectToVisible(new Rectangle(0, textPane.getHeight()-2, 1, 1));

        }
      });

    }


    

    public JMenuItem getRedoMenu() {
        return redoMenu;
    }

    public JMenuItem getUndoMenu() {
        return undoMenu;
    }

    public PropertiesTableModel getModel() {
        return model;
    }

    

    public void setFileName(String projectTitle) {
        if ((this.fileName == null && projectTitle != null) ||
            (this.fileName != null && projectTitle == null) ||
            (!this.fileName.equals(projectTitle))){
            this.fileName = projectTitle;
            updateTitle();
        }
    }

    public boolean isSaved() {
        return saved;
    }

    

    public void setSaved(boolean saved) {
        if(saved != this.saved){
            this.saved = saved;
            updateTitle();
        }
    }

     private void updateTitle(){
        setTitle("Semantic Sensor Simulator - " + fileName + " - " + (saved?"":"*"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainSplitPanel = new javax.swing.JSplitPane();
        leftSplitPanel = new javax.swing.JSplitPane();
        areaSimulationPanel = panel;
        jScrollPane1 = new javax.swing.JScrollPane();
        textPane = new javax.swing.JTextPane();
        rightSplitPanel = new javax.swing.JSplitPane();
        propiertiesScrollPanel = new javax.swing.JScrollPane();
        propiertiesTable = new javax.swing.JTable();
        optionsPanel = new javax.swing.JPanel();
        deleteButton = new javax.swing.JButton();
        imoteButton = new javax.swing.JButton();
        irisButton = new javax.swing.JButton();
        linkButton = new javax.swing.JButton();
        rainButton = new javax.swing.JButton();
        quakeButton = new javax.swing.JButton();
        fireButton = new javax.swing.JButton();
        mainMenuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveasMenuItem = new javax.swing.JMenuItem();
        saveontologyMenuItem = new javax.swing.JMenuItem();
        fileSeparator = new javax.swing.JPopupMenu.Separator();
        closeMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        undoMenu = new javax.swing.JMenuItem();
        redoMenu = new javax.swing.JMenuItem();
        simulationMenu = new javax.swing.JMenu();
        startMenuItem = new javax.swing.JMenuItem();
        stopMenuItem = new javax.swing.JMenuItem();
        queriesMenu = new javax.swing.JMenu();
        nodesMenu = new javax.swing.JMenu();
        burnedNodesMenuItem = new javax.swing.JMenuItem();
        wetNodesMenuItem = new javax.swing.JMenuItem();
        fallenNodesMenuItem = new javax.swing.JMenuItem();
        eventsMenu = new javax.swing.JMenu();
        fireMenuItem = new javax.swing.JMenuItem();
        rainMenuItem = new javax.swing.JMenuItem();
        quakeMenuItem = new javax.swing.JMenuItem();
        advancedQueryMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Semantic Sensor Simulator");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        mainSplitPanel.setDividerLocation(500);
        mainSplitPanel.setResizeWeight(1.0);

        leftSplitPanel.setDividerLocation(400);
        leftSplitPanel.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        leftSplitPanel.setResizeWeight(1.0);

        javax.swing.GroupLayout areaSimulationPanelLayout = new javax.swing.GroupLayout(areaSimulationPanel);
        areaSimulationPanel.setLayout(areaSimulationPanelLayout);
        areaSimulationPanelLayout.setHorizontalGroup(
            areaSimulationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 497, Short.MAX_VALUE)
        );
        areaSimulationPanelLayout.setVerticalGroup(
            areaSimulationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 399, Short.MAX_VALUE)
        );

        leftSplitPanel.setTopComponent(areaSimulationPanel);

        textPane.setDocument(document);
        textPane.setEditable(false);
        textPane.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textPaneKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(textPane);

        leftSplitPanel.setRightComponent(jScrollPane1);

        mainSplitPanel.setLeftComponent(leftSplitPanel);

        rightSplitPanel.setDividerLocation(375);
        rightSplitPanel.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        propiertiesTable.setModel(model);
        propiertiesScrollPanel.setViewportView(propiertiesTable);

        rightSplitPanel.setBottomComponent(propiertiesScrollPanel);

        deleteButton.setText("Borrar");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        imoteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/unavarra/mti/iws/resources/imoteIcon.png"))); // NOI18N
        imoteButton.setText(" Imote");
        imoteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imoteButtonActionPerformed(evt);
            }
        });

        irisButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/unavarra/mti/iws/resources/irisIcon.png"))); // NOI18N
        irisButton.setText("Iris");
        irisButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                irisButtonActionPerformed(evt);
            }
        });

        linkButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/unavarra/mti/iws/resources/linkIcon.png"))); // NOI18N
        linkButton.setText(" Enlace");
        linkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                linkButtonActionPerformed(evt);
            }
        });

        rainButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/unavarra/mti/iws/resources/rainIcon.png"))); // NOI18N
        rainButton.setText(" Lluvia");
        rainButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rainButtonActionPerformed(evt);
            }
        });

        quakeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/unavarra/mti/iws/resources/quakeIcon.png"))); // NOI18N
        quakeButton.setText(" Temblor");
        quakeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quakeButtonActionPerformed(evt);
            }
        });

        fireButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/unavarra/mti/iws/resources/fireIcon.png"))); // NOI18N
        fireButton.setText("Fuego");
        fireButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fireButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(irisButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(imoteButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(linkButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(fireButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(rainButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(quakeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                .addContainerGap())
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imoteButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(irisButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(linkButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fireButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rainButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(quakeButton)
                .addGap(18, 18, 18)
                .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(46, 46, 46))
        );

        rightSplitPanel.setLeftComponent(optionsPanel);

        mainSplitPanel.setRightComponent(rightSplitPanel);

        fileMenu.setMnemonic('A');
        fileMenu.setText("Archivo");

        newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newMenuItem.setMnemonic('N');
        newMenuItem.setText("Nuevo");
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(newMenuItem);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setMnemonic('A');
        openMenuItem.setText("Abrir");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setMnemonic('G');
        saveMenuItem.setText("Guardar");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);

        saveasMenuItem.setMnemonic('u');
        saveasMenuItem.setText("Guardar Como..");
        saveasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveasMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveasMenuItem);

        saveontologyMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        saveontologyMenuItem.setText("Guardar Ontologia");
        saveontologyMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveontologyMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveontologyMenuItem);
        fileMenu.add(fileSeparator);

        closeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        closeMenuItem.setMnemonic('S');
        closeMenuItem.setText("Salir");
        closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(closeMenuItem);

        mainMenuBar.add(fileMenu);

        jMenu1.setText("Editar");

        undoMenu.setText("Deshacer");
        undoMenu.setEnabled(false);
        undoMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                undoMenuActionPerformed(evt);
            }
        });
        jMenu1.add(undoMenu);

        redoMenu.setText("Rehacer");
        redoMenu.setEnabled(false);
        redoMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                redoMenuActionPerformed(evt);
            }
        });
        jMenu1.add(redoMenu);

        mainMenuBar.add(jMenu1);

        simulationMenu.setMnemonic('S');
        simulationMenu.setText("Simulación");

        startMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F6, 0));
        startMenuItem.setMnemonic('E');
        startMenuItem.setText("Empezar");
        startMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startMenuItemActionPerformed(evt);
            }
        });
        simulationMenu.add(startMenuItem);

        stopMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F7, 0));
        stopMenuItem.setMnemonic('D');
        stopMenuItem.setText("Detener");
        stopMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopMenuItemActionPerformed(evt);
            }
        });
        simulationMenu.add(stopMenuItem);

        mainMenuBar.add(simulationMenu);

        queriesMenu.setMnemonic('C');
        queriesMenu.setText("Consultas");

        nodesMenu.setText("Nodos");

        burnedNodesMenuItem.setText("Con fuego");
        burnedNodesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                burnedNodesMenuItemActionPerformed(evt);
            }
        });
        nodesMenu.add(burnedNodesMenuItem);

        wetNodesMenuItem.setText("Con Humedad");
        wetNodesMenuItem.setActionCommand("Nodos con humedad");
        wetNodesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wetNodesMenuItemActionPerformed(evt);
            }
        });
        nodesMenu.add(wetNodesMenuItem);

        fallenNodesMenuItem.setText("Caídos");
        fallenNodesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fallenNodesMenuItemActionPerformed(evt);
            }
        });
        nodesMenu.add(fallenNodesMenuItem);

        queriesMenu.add(nodesMenu);

        eventsMenu.setText("Eventos");

        fireMenuItem.setText("Incendio");
        fireMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fireMenuItemActionPerformed(evt);
            }
        });
        eventsMenu.add(fireMenuItem);

        rainMenuItem.setText("Lluvia");
        rainMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rainMenuItemActionPerformed(evt);
            }
        });
        eventsMenu.add(rainMenuItem);

        quakeMenuItem.setText("Temblor");
        quakeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quakeMenuItemActionPerformed(evt);
            }
        });
        eventsMenu.add(quakeMenuItem);

        queriesMenu.add(eventsMenu);

        advancedQueryMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F11, 0));
        advancedQueryMenuItem.setText("Avanzada");
        advancedQueryMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                advancedQueryMenuItemActionPerformed(evt);
            }
        });
        queriesMenu.add(advancedQueryMenuItem);

        mainMenuBar.add(queriesMenu);

        helpMenu.setMnemonic('y');
        helpMenu.setText("Ayuda");

        aboutMenuItem.setMnemonic('A');
        aboutMenuItem.setText("Acerca de..");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        mainMenuBar.add(helpMenu);

        setJMenuBar(mainMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainSplitPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 656, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainSplitPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fireButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fireButtonActionPerformed
        manager.getRunner().setInserting(new Fire());
    }//GEN-LAST:event_fireButtonActionPerformed

    private void undoMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_undoMenuActionPerformed
        manager.getUndo().undo();
    }//GEN-LAST:event_undoMenuActionPerformed

    private void redoMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redoMenuActionPerformed
        manager.getUndo().redo();
    }//GEN-LAST:event_redoMenuActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        manager.getRunner().getEditor().deleteSelection();
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void imoteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imoteButtonActionPerformed
        Node n = new Node();
        n.setType(Node.TYPE_IMOTE);
        manager.getRunner().setInserting(n);
    }//GEN-LAST:event_imoteButtonActionPerformed

    private void irisButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irisButtonActionPerformed
        Node n = new Node();
        n.setType(Node.TYPE_IRIS);
        manager.getRunner().setInserting(n);
    }//GEN-LAST:event_irisButtonActionPerformed

    private void linkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_linkButtonActionPerformed
        manager.getRunner().setInserting(new Link());
    }//GEN-LAST:event_linkButtonActionPerformed

    private void rainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rainButtonActionPerformed
        manager.getRunner().setInserting(new Rain());
    }//GEN-LAST:event_rainButtonActionPerformed

    private void quakeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quakeButtonActionPerformed
        manager.getRunner().setInserting(new Quake());
    }//GEN-LAST:event_quakeButtonActionPerformed

    private void textPaneKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textPaneKeyReleased
        if(evt.getKeyCode() == KeyEvent.VK_C){
            try {
                document.remove(0, document.getLength());
            } catch (BadLocationException ex) {
                ex.printStackTrace();
            }
        }
    }//GEN-LAST:event_textPaneKeyReleased

    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
        manager.newModel();
    }//GEN-LAST:event_newMenuItemActionPerformed

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        manager.loadModel();
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        manager.saveModel();
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void saveasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveasMenuItemActionPerformed
        manager.saveModelAs();
    }//GEN-LAST:event_saveasMenuItemActionPerformed

    private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed
        manager.closeOperation();
    }//GEN-LAST:event_closeMenuItemActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        manager.closeOperation();
    }//GEN-LAST:event_formWindowClosing

    private void startMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startMenuItemActionPerformed
        manager.startSimulation();
    }//GEN-LAST:event_startMenuItemActionPerformed

    private void stopMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopMenuItemActionPerformed
        manager.stopSimulation();
    }//GEN-LAST:event_stopMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        manager.openAboutDialog();
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void burnedNodesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_burnedNodesMenuItemActionPerformed
        manager.checkBurnedNodes();
    }//GEN-LAST:event_burnedNodesMenuItemActionPerformed

    private void wetNodesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wetNodesMenuItemActionPerformed
        manager.checkWetNodes();
    }//GEN-LAST:event_wetNodesMenuItemActionPerformed

    private void fallenNodesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fallenNodesMenuItemActionPerformed
        manager.checkFallenNodes();
    }//GEN-LAST:event_fallenNodesMenuItemActionPerformed

    private void fireMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fireMenuItemActionPerformed
        manager.onFire();
    }//GEN-LAST:event_fireMenuItemActionPerformed

    private void rainMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rainMenuItemActionPerformed
        manager.onRain();
    }//GEN-LAST:event_rainMenuItemActionPerformed

    private void quakeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quakeMenuItemActionPerformed
        manager.onQuake();
    }//GEN-LAST:event_quakeMenuItemActionPerformed

    private void advancedQueryMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedQueryMenuItemActionPerformed
        manager.openAdvancedQueryDialog();
    }//GEN-LAST:event_advancedQueryMenuItemActionPerformed

    private void saveontologyMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveontologyMenuItemActionPerformed
        manager.saveModelAsOntology();
    }//GEN-LAST:event_saveontologyMenuItemActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem advancedQueryMenuItem;
    private javax.swing.JPanel areaSimulationPanel;
    private javax.swing.JMenuItem burnedNodesMenuItem;
    private javax.swing.JMenuItem closeMenuItem;
    private javax.swing.JButton deleteButton;
    private javax.swing.JMenu eventsMenu;
    private javax.swing.JMenuItem fallenNodesMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JPopupMenu.Separator fileSeparator;
    private javax.swing.JButton fireButton;
    private javax.swing.JMenuItem fireMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton imoteButton;
    private javax.swing.JButton irisButton;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane leftSplitPanel;
    private javax.swing.JButton linkButton;
    private javax.swing.JMenuBar mainMenuBar;
    private javax.swing.JSplitPane mainSplitPanel;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JMenu nodesMenu;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JScrollPane propiertiesScrollPanel;
    private javax.swing.JTable propiertiesTable;
    private javax.swing.JButton quakeButton;
    private javax.swing.JMenuItem quakeMenuItem;
    private javax.swing.JMenu queriesMenu;
    private javax.swing.JButton rainButton;
    private javax.swing.JMenuItem rainMenuItem;
    private javax.swing.JMenuItem redoMenu;
    private javax.swing.JSplitPane rightSplitPanel;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JMenuItem saveasMenuItem;
    private javax.swing.JMenuItem saveontologyMenuItem;
    private javax.swing.JMenu simulationMenu;
    private javax.swing.JMenuItem startMenuItem;
    private javax.swing.JMenuItem stopMenuItem;
    private javax.swing.JTextPane textPane;
    private javax.swing.JMenuItem undoMenu;
    private javax.swing.JMenuItem wetNodesMenuItem;
    // End of variables declaration//GEN-END:variables

}
